package com.promote.common.properties.factory.config;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.stereotype.Component;

import com.promote.common.properties.FilePropertiesMap;
import com.promote.common.properties.initializer.PlatformInitFactory;

/**
 * @Description: 项目初始化，加载配置文件
 * @Package com.tarena.platform.base.initfactory
 * @File: PlatformInitializer
 * @Version V1.0
 * @author: chenyao
 * @date: 2019-04-28 15:04
 * @Copyright: 2019 www.tedu.cn Inc. All rights reserved, Designed By
 *             www.tedu.cn 注意：本内容仅限于达内时代科技集团内部传阅，禁止外泄以及用于其他的商业目
 */
@Component
public class PlatformPropertyPlaceholder extends PropertyPlaceholderConfigurer {
	private Logger log = LoggerFactory.getLogger(this.getClass());

	@Override
	protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) {
		String propVal = super.resolvePlaceholder(placeholder, props, systemPropertiesMode);
		if (propVal == null || propVal.isEmpty()) {
			if (!PlatformInitFactory.hasInit) {
				log.info("配置文件未初始化，开始初始化。。。");
				PlatformInitFactory.init();
			}
			propVal = FilePropertiesMap.getValue(placeholder);

		}
		return propVal;
	}

}